package com.ftg.learn.day10.pattern.singleton;

/**
 * 单例
 *
 * @author 布衣
 */
public class MyselfSingleton {

    private MyselfSingleton() {
    }

    /**
     * volatile 保证线程可见性
     */
    private volatile static MyselfSingleton m;

    //dcl double check locking
    public static MyselfSingleton getInstance() {
        if (null == m) {
            synchronized (m) {
                if (null == m) {
                    m = new MyselfSingleton();
                }
            }
        }
        return m;
    }


    public int add(int x, int y) {
        return x + y;
    }

}

